<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 定义四个按钮 -->
    <button class="btn1">按钮1</button>
    <button class="btn2">按钮2</button>
    <button class="btn3">按钮3</button>
    <button class="btn4">按钮4</button>
    484f961ed70e725c06878b47c1ec7002
    <script>
        /* (function name() {
            console.log("first")
        })() */ 
       /* let btnEl = document.querySelector(".btn1");

       btnEl.onclick = function () {
        console.log("按钮被点击")
       } */

       let btnEls = document.querySelectorAll("button");
       for (let i = 0; i < btnEls.length; i++) {

        let btn = btnEls[i];

        (function(m) {

            btn.onclick = function () { // 立即执行函数
                console.log(`按钮${m+1}被点击`)
            }
        })(i)
    
       }
       


    </script>
</body>
</html>